/*
 * $Id: DeleteCommand.java 84 2008-02-22 01:15:06Z jasta $
 *
 * Copyright (C) 2008 Josh Guilfoyle <jasta@devtcg.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

package org.devtcg.syncml.protocol;

import org.devtcg.syncml.protocol.SyncItem;

import java.util.ArrayList;
import org.w3c.dom.*;

public class DeleteCommand extends BaseCommand
{
	protected ArrayList<SyncItem> mItems =
	  new ArrayList<SyncItem>(1);

	protected String mMimeType;

	public DeleteCommand(Element command)
	{
		super("Delete");

		NodeList children = command.getChildNodes();

		for (int i = 0; i < children.getLength(); i++)
		{
			Node n = children.item(i);

			if (n.getNodeName().equals("CmdID") == true)
				mID = Long.valueOf(((Text)n.getFirstChild()).getNodeValue());
			else if (n.getNodeName().equals("Meta") == true)
				mMimeType = ((Text)n.getFirstChild().getFirstChild()).getNodeValue();
			else if (n.getNodeName().equals("Item") == true)
			{
				SyncItem item = new SyncItem((Element)n);

				if (mMimeType != null)
					item.setMimeType(mMimeType);

				mItems.add(item);
			}
		}
	}

	public int getItemLength()
	{
		return mItems.size();
	}

	public SyncItem getItem(int n)
	{
		return mItems.get(n);
	}

	public String toString()
	{
		return null;
	}
}
